package com.lxmes.gs.controller;

import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import com.lxmes.gs.domain.workingHoursSubmissionVO.*;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.gs.domain.WorkingHoursSubmission;
import com.lxmes.gs.service.IWorkingHoursSubmissionService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 工时提报Controller
 * 
 * @author wdf
 * @date 2023-04-24
 */
@Api(tags = "工时提报")    
@RestController
@RequestMapping("/gs/workingHoursSubmission")
public class WorkingHoursSubmissionController extends BaseController{
    @Autowired
    private IWorkingHoursSubmissionService workingHoursSubmissionService;

    /**
     * 查询工时提报列表
     */
    @ApiOperation("查询工时提报列表")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkingHoursSubmissionSearchVO workingHoursSubmission){
        startPage();
        List<WorkingHoursSubmission> list = workingHoursSubmissionService.selectWorkingHoursSubmissionList(BeanUtil.copyProperties(workingHoursSubmission,WorkingHoursSubmission.class));
        return getDataTable(Convert.convert(new TypeReference<List<WorkingHoursSubmissionResultVO>>() {},list));
}

    /**
     * 导出工时提报列表
     */
    @ApiOperation("导出工时提报列表")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:export')")
    @Log(title = "工时提报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkingHoursSubmission workingHoursSubmission){
        List<WorkingHoursSubmission> list = workingHoursSubmissionService.selectWorkingHoursSubmissionList(workingHoursSubmission);
        List<WorkingHoursSubmissionExportVO> exportList = Convert.convert(new TypeReference<List<WorkingHoursSubmissionExportVO>>() {}, list);
        ExcelUtil<WorkingHoursSubmissionExportVO> util = new ExcelUtil<WorkingHoursSubmissionExportVO>(WorkingHoursSubmissionExportVO.class);
        util.exportExcel(response, exportList, "工时提报数据");
    }

    /**
     * 获取工时提报详细信息
     */
    @ApiOperation("获取工时提报详细信息")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(workingHoursSubmissionService.selectWorkingHoursSubmissionById(id));
    }

    /**
     * 新增工时提报
     */
    @ApiOperation("新增工时提报")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:add')")
    @Log(title = "工时提报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkingHoursSubmissionCreateVO workingHoursSubmission){
        return toAjax(workingHoursSubmissionService.insertWorkingHoursSubmission(BeanUtil.copyProperties(workingHoursSubmission,WorkingHoursSubmission.class)));
    }

    /**
     * 修改工时提报
     */
    @ApiOperation("修改工时提报")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:edit')")
    @Log(title = "工时提报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkingHoursSubmissionUpdateVO workingHoursSubmission){
        return toAjax(workingHoursSubmissionService.updateWorkingHoursSubmission(BeanUtil.copyProperties(workingHoursSubmission,WorkingHoursSubmission.class)));
    }

    /**
     * 删除工时提报
     */
    @ApiOperation("删除工时提报")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:remove')")
    @Log(title = "工时提报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(workingHoursSubmissionService.deleteWorkingHoursSubmissionByIds(ids));
    }

    /**
     * 导入工时提报
     */
    @Log(title = "工时提报", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception{
        ExcelUtil<WorkingHoursSubmissionImportVO> util = new ExcelUtil<>(WorkingHoursSubmissionImportVO.class);
        List<WorkingHoursSubmissionImportVO> workingHoursSubmissionList = util.importExcel(file.getInputStream());
        String message = workingHoursSubmissionService.imporIteminfo(Convert.convert(new TypeReference<List<WorkingHoursSubmission>>() {},workingHoursSubmissionList), updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException{
        ExcelUtil<WorkingHoursSubmissionImportVO> util = new ExcelUtil<>(WorkingHoursSubmissionImportVO.class);
        util.importTemplateExcel(response,"工时提报");
    }
    /**
     * 工时提报审核
     */
    @ApiOperation("工时提报审核")
    @PreAuthorize("@ss.hasPermi('gs:workingHoursSubmission:audit')")
    @Log(title = "工时提报审核")
	@PostMapping("/auditWorkingHoursSubmission/{ids}")
    public AjaxResult auditWorkingHoursSubmission(@PathVariable Long[] ids){
        return toAjax(workingHoursSubmissionService.auditWorkingHoursSubmission(ids));
    }
}
